﻿<UserControl x:Class="DotConsulting.VisualStudio.BuildOutputCopy.View.BuildOutputCopyView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:localConverter="clr-namespace:DotConsulting.VisualStudio.BuildOutputCopy.View.Converter"
             xmlns:localModel="clr-namespace:DotConsulting.VisualStudio.BuildOutputCopy.Model"
             xmlns:System="clr-namespace:System;assembly=mscorlib"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300"
             x:Name="Root"
             >
    <UserControl.Resources>
        <CollectionViewSource x:Key="groupedReferences" Source="{Binding AllOutputFiles}">
            <CollectionViewSource.GroupDescriptions>
                <PropertyGroupDescription PropertyName="Parent" />
            </CollectionViewSource.GroupDescriptions>
        </CollectionViewSource>
        <BooleanToVisibilityConverter x:Key="VisibilityOfBool" />
        <localConverter:MessageStateToBrushConverter x:Key="MsgStateToBrush" />
        <ObjectDataProvider x:Key="SearchScopeEnum" MethodName="GetValues" ObjectType="{x:Type System:Enum}">
            <ObjectDataProvider.MethodParameters>
                <x:Type TypeName="localModel:SearchScope"/>
            </ObjectDataProvider.MethodParameters>
        </ObjectDataProvider>
    </UserControl.Resources>

    <Grid Background="White" >
        <Grid.RowDefinitions>
            <RowDefinition Height="30" />
            <RowDefinition Height="30" />
            <RowDefinition Height="30" />
            <RowDefinition Height="*" />
            <RowDefinition Height="50" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="190" />
            <ColumnDefinition />
            <ColumnDefinition Width="50" />
        </Grid.ColumnDefinitions>
        <TextBlock Grid.Column="0" Grid.Row="0" VerticalAlignment="Center" HorizontalAlignment="Right">Current Configuration:</TextBlock>
        <StackPanel Orientation="Horizontal" Grid.Column="1" Grid.Row="0" >
            <TextBlock VerticalAlignment="Center" HorizontalAlignment="Left" Margin="5 0 5 0" Foreground="DarkBlue" Text="{Binding ActiveConfiguration}" />
        </StackPanel>
        <TextBlock Grid.Column="0" Grid.Row="1" VerticalAlignment="Center" HorizontalAlignment="Right">Destination folder:</TextBlock>
        <TextBox Grid.Column="1" Grid.Row="1" Height="22" MaxLines="1" Margin="5 0 5 0" Text="{Binding DestinationFolder, Mode=TwoWay}" Foreground="DarkBlue"/>
        <Button Grid.Column="2" Grid.Row="1" Command="{Binding BrowseDirectoryCommand}" Width="22" Height="20" HorizontalAlignment="Left">...</Button>
        <StackPanel Orientation="Horizontal" Grid.Column="0" Grid.Row="2" HorizontalAlignment="Left" >
            <Button Height="22" Width="60" Margin="5 0 0 0" Command="{Binding RefreshCommand}">Reload</Button>
            <TextBlock Width="110" Margin="10 0 5 0" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="DarkGray">
                <TextBlock.Text>
                    <MultiBinding StringFormat="{}({0} of {1} selected)" >
                        <Binding Path="TotalSelected" />
                        <Binding Path="TotalFiles" />
                    </MultiBinding>
                </TextBlock.Text>
            </TextBlock>
        </StackPanel>
        <StackPanel Orientation="Horizontal" Grid.Column="1" Grid.Row="2" Grid.ColumnSpan="2">
            <Button Height="22" Command="{Binding CopyFilesCommand}" Width="70">Copy</Button>
            <TextBlock Margin="15 0 0 0" TextAlignment="Left" VerticalAlignment="Center" Foreground="{Binding MessageInfoState, Converter={StaticResource MsgStateToBrush}}" Text="{Binding MessageInfo}" />
        </StackPanel>
        <ListView Grid.Row="3" Grid.ColumnSpan="3" ItemsSource="{Binding Source={StaticResource groupedReferences}}" IsTextSearchEnabled="False" SelectionMode="Single" SelectedItem="{Binding SelectedItem}" SelectionChanged="ListView_SelectionChanged">
            <ListView.GroupStyle>
                <GroupStyle>
                    <GroupStyle.ContainerStyle>
                        <Style TargetType="{x:Type GroupItem}">
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="{x:Type GroupItem}">
                                        <Expander IsExpanded="True">
                                            <Expander.Header>
                                                <DockPanel>
                                                    <StackPanel Orientation="Horizontal">
                                                        <TextBlock Foreground="DarkBlue" FontWeight="Bold" Text="{Binding Path=Name.Name}" />
                                                        <TextBlock Foreground="Gray" Text=" (" />
                                                        <TextBlock Foreground="Gray" Text="{Binding Path=Name.OutputDir}" />
                                                        <TextBlock Foreground="Gray" Text=")" />
                                                    </StackPanel>
                                                </DockPanel>
                                            </Expander.Header>
                                            <Expander.Content>
                                                <ItemsPresenter />
                                            </Expander.Content>
                                        </Expander>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </GroupStyle.ContainerStyle>
                </GroupStyle>
            </ListView.GroupStyle>
            <ListView.View>
                <GridView AllowsColumnReorder="False">
                    <GridViewColumn Header="To Copy">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal">
                                    <CheckBox IsChecked="{Binding Selected, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                              Command="{Binding ElementName=Root,Path=DataContext.CheckChangedCommand}"
                                              CommandParameter="{Binding RelativeSource={RelativeSource Self}}"/>
                                </StackPanel>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn Header="Filename">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Text="{Binding Filename}"/>
                                </StackPanel>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn Header="Timestamp">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Text="{Binding BuildTS}"/>
                                </StackPanel>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                </GridView>
            </ListView.View>
        </ListView>
        <Border Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="3" BorderBrush="Black" BorderThickness="0 1 0 0" Margin="5 5 5 5" >
            <StackPanel Orientation="Horizontal" VerticalAlignment="Center" Margin="0 5 0 10" Height="24">
                <TextBlock Margin="5 0 10 0" VerticalAlignment="Center">Search:</TextBlock>
                <ComboBox Width="100"  Margin="0 0 10 0" Height="22" ItemsSource="{Binding Source={StaticResource SearchScopeEnum}}" SelectedItem="{Binding Path=SearchScope,UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" />
                <TextBox Width="150" Text="{Binding SearchText, UpdateSourceTrigger=PropertyChanged}"></TextBox>
                <Button Width="18" Height="22" Margin="5 0 5 0" Command="{Binding PreviousSearchResultCommand}" FontSize="10">&lt;</Button>
                <Button Width="18" Height="22" Command="{Binding NextSearchResultCommand}" FontSize="10">&gt;</Button>
                <TextBlock Margin="5 0 0 0"  Foreground="DarkGray" Width="100" VerticalAlignment="Center">
                    <TextBlock.Text>
                        <MultiBinding StringFormat="{}({0} found)" >
                            <Binding Path="SearchResultCount" />
                        </MultiBinding>
                    </TextBlock.Text>
                </TextBlock>
                <Button Width="60" Height="22" Command="{Binding UncheckFoundCommand}">Uncheck</Button>
                <Button Width="60" Height="22" Command="{Binding CheckFoundCommand}" Margin="5 0 0 0">Check</Button>
            </StackPanel>
        </Border>
        <Border Background="#44000000" Grid.ColumnSpan="3" Grid.RowSpan="5" BorderThickness="0" Visibility="{Binding Busy, Converter={StaticResource VisibilityOfBool}}">
            <StackPanel Orientation="Vertical"  VerticalAlignment="Center" >
                <TextBlock Text="Copying..." FontSize="32" HorizontalAlignment="Center" Foreground="White"/>
                <ProgressBar Height="16" Width="150" Margin="0 10 0 0" IsIndeterminate="False" Minimum="0" Maximum="{Binding MaxProgress}" Value="{Binding CurrentProgress}"/>
            </StackPanel>
        </Border>
    </Grid>


</UserControl>
